<?php

if (!defined('BASEPATH'))
	exit('No Direct Access Allowed !');

/**
*  
*/
class login extends CI_Controller
{
	
	function __construct()
	{

		parent::__construct();
		 $this->load->model('m_login');
	}


	function index(){
		$cek = $this->session->userdata('logged_in');
		if (empty($cek)) {
			$this->load->view("login/index");
		} else {
			header('location:' . site_url('dashboard'));
		}
	}

	function do_login() {
		$cek = $this->session->userdata('logged_in');
		if (empty($cek)) {
			$this->form_validation->set_rules('username', 'Username', 'required');
			$this->form_validation->set_rules('password', 'Password', 'required');

			if ($this->form_validation->run() == FALSE) {
				$this->load->view("login/index");
			} else {
				$u = $this->input->post('username');
				$p = $this->input->post('password');
				$this->m_login->getLoginData($u, $p);
			}
		} else {
			redirect('dashboard');
		}
	}

	function logout(){
		 $this->session->sess_destroy();
        header('location:' . site_url(''));
	}
}